﻿@model ViewModel
@functions{
    string PublicFeed() {
        var feedBurner = Model.Blog.Property().FeedBurner as string;

        return string.IsNullOrWhiteSpace(feedBurner) ? Url.Action("index", "feed") : feedBurner;
    }
}
<!DOCTYPE html>
<html class="no-js" dir="ltr" lang="en">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="cleartype" content="on" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="keywords" content="@(ViewBag.MetaKeywords ?? Model.Blog.MetaKeywords)" />
    <meta name="description" content="@(ViewBag.MetaDescription ?? Model.Blog.MetaDescription)" />
    <meta name="author" content="@(ViewBag.Author ?? Model.Blog.Author)" />
    <meta name="copyright" content="@(ViewBag.Author ?? Model.Blog.Author)" />
    <meta name="generator" content="@ApplicationInfo.FullName" />
    <meta name="HandheldFriendly" content="true" />
    <meta name="MobileOptimized" content="320" />
    <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1" />
    @RenderSection("Meta", false)
    @PageTitle()
    <link rel="stylesheet" href="@Url.StyleSheet("site")" />
    <script src="@Url.JavaScript("modernizr")"></script>
    @GoogleFonts()
    @TypeKitFonts()
    <link rel="alternate" href="@PublicFeed()" type="application/atom+xml" title="@Model.Blog.Title Feed" />
    <link rel="shortcut icon" href="@Url.Image("favicon.ico")" />
    <link rel="apple-touch-icon" href="@Url.Image("apple-touch-icon.ico")" />
    @RenderSection("StyleSheets", false)
    <script src="@Url.JavaScript("jquery")"></script>
    <!--[if (gte IE 6)&(lte IE 8)]>
        <script src="@Url.JavaScript("DOMAssistant")"></script>
        <script src="@Url.JavaScript("selectivizr")"></script>
    <![endif]-->
</head>
<body>
    <div id="wrapper">
        <div id="container">
            <header role="banner">
                <hgroup>
                    <h1>@Model.Blog.Title</h1>
                    @Tagline()
                </hgroup>
            </header>
            <nav role="navigation">
                <ul>
                    <li><a href="@Url.Content("~/")" rel="home">Home</a></li>
                    <li>@Html.ActionLink("Archives", "index", "archives", null, new { rel = "archives" })</li>
                    @Contact()
                </ul>
                <ul>
                    <li><a href="@PublicFeed()" rel="alternate">Subscribe to my feed</a></li>
                    @Twitter()
                </ul>
            </nav>
            <div role="main">
                @RenderBody()
            </div>
        </div>
    </div>
    @Scripts()
    @RenderSection("JavaScripts", false)
</body>
</html>

@helper PageTitle() {

    var title = (ViewBag.Title as string) ?? string.Empty;

    if (!string.IsNullOrWhiteSpace(title))
    {
        title += " - ";
    }

    title += Model.Blog.Title;

    <title>@title</title>
}

@helper Tagline() {

    var tagline = Model.Blog.Tagline;

    if (string.IsNullOrWhiteSpace(tagline)) {
        return;
    }

    <h2>@tagline</h2>
}

@helper GoogleFonts() {

    var googleFonts = Model.Blog.Property().GoogleFonts as IEnumerable<string>;

    if ((googleFonts == null) || !googleFonts.Any()) {
        return;
    }

    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=@string.Join("|", googleFonts)"/>
}

@helper TypeKitFonts() {

    var typekitCode = Model.Blog.Property().TypekitCode as string;

    if (string.IsNullOrWhiteSpace(typekitCode)) {
        return;
    }

    <script src="http://use.typekit.com/@(typekitCode).js"></script>
    <script>try{Typekit.load();}catch(e) {}</script>
}

@helper Contact() {

    var email = Model.Blog.Email;

    if (string.IsNullOrWhiteSpace(email)) {
        return;
    }

    <li>@Html.ActionLink("Contact", "index", "contact")</li>
}

@helper Twitter() {
    var twitter = Model.Blog.Property().Twitter as string;

    if (string.IsNullOrWhiteSpace(twitter)) {
        return;
    }

    <li><a href="http://twitter.com/@twitter" rel="me external">Follow me on Twitter</a></li>
}

@helper Scripts() {

    var feedBurner = Model.Blog.Property().FeedBurner as string;
    var twitter = Model.Blog.Property().Twitter as string;

    var scripts = new StringBuilder();

    scripts.Append("Modernizr.load([{");

    scripts.Append("load: [");
    scripts.Append("'" + Url.JavaScript("jquery.tools.tooltip") + "'");

    if (!string.IsNullOrWhiteSpace(feedBurner)) {
        scripts.Append(",");
        scripts.Append("'" + Url.JavaScript("feedburner") + "'");
    }

    if (!string.IsNullOrWhiteSpace(twitter)) {
        scripts.Append(",");
        scripts.Append("'" + Url.JavaScript("twitter") + "'");
    }

    scripts.Append("], ");

    scripts.Append("complete: function() {");
    scripts.Append("(function($){");

    var endPoint = Url.Action("get", "contentproxy");

    if (!string.IsNullOrWhiteSpace(feedBurner)) {
        scripts.Append("$('nav > ul + ul li:first-child a').feedburner({ url: '" + endPoint + "' });");
    }

    if (!string.IsNullOrWhiteSpace(twitter)) {
        scripts.Append("$('nav > ul + ul li:last-child a').twitter({ url: '" + endPoint + "'});");
    }

    scripts.Append("$('a[title]').tooltip({position: 'bottom center', offset: [5, 0]});");

    scripts.Append("})(jQuery);");
    scripts.Append("}");

    scripts.Append("}]);");

    <script>@Html.Raw(scripts.ToString())</script>
}